
import { getSkillName } from "../系统功能/GlobalObjectManage";
import { DamageChangeData } from "./DamageManage";

export interface SkillData {
    name: string,
    //是否指向性技能
    isDirect: false,
    onSkillExecute: Function,
    onSkillDamage: Function
}
export class CustomSkillManage {
    skillExecuteMap: Map<string, Function>;
    skillDamageMap: Map<string, Function>;
    skillSetMap: Map<string, SkillData>;

    constructor(customSkillSet: Array<any>) {
        this.skillDamageMap = new Map<string, Function>();
        this.skillExecuteMap = new Map<string, Function>();
        this.skillSetMap = new Map<string, any>();
        for (let i = 0; i < customSkillSet.length; i++) {
            let item = customSkillSet[i];
            let data: SkillData = item as SkillData;
            this.skillSetMap.set(data.name, data);


            if (item.onSkillExecute) {
                this.skillExecuteMap.set(item.name, item.onSkillExecute);
            }
            if (item.onSkillDamage) {
                this.skillDamageMap.set(item.name, item.onSkillDamage);
            }
        }
    }

    getSkillSet(name: string): SkillData {
        return this.skillSetMap.get(name);
    }

    onSkillExecute(Source: TActor, Target: TActor, AMethod: string, nParam1: number, nParam2:
        number, sParam1: string, sParam2: string): void {
        // console.log(AMethod + " " + GameLib.TickCount)
        let fuc = this.skillExecuteMap.get(AMethod);
        // console.log(!!fuc)
        if (fuc) {
            fuc(Source, Target, AMethod, nParam1, nParam2, sParam1, sParam2)
        }
    }

    onSkillDamage(ActorObject: TActor, ADamageSource: TActor, Tag: number, SkillID: number,
        SkillLevel: number, Value: number)
        : Array<DamageChangeData> {

        if (!SkillID) {
            return null;
        }
        let skillName = getSkillName(SkillID);
        if (!skillName) {
            return null;
        }
        // console.log(skillName)
        let fuc = this.skillDamageMap.get(skillName);
        // console.log(fuc)
        if (fuc) {
            return fuc(ActorObject, ADamageSource, Tag, SkillID, SkillLevel, Value, skillName);
        }
        return null;
    }
}